#include<bits/stdc++.h>
using namespace std;
#define ll long long

struct cow{
  ll a;
  ll b;
};

bool cmp(cow x,cow y){
  return (double)x.b/x.a>(double)y.b/y.a;
}


int main(){
  ll n;
  cin>>n;
  vector<cow> vec(n);
  for(ll i=0;i<n;i++)
    cin>>vec[i].a>>vec[i].b;
  sort(vec.begin(),vec.end(),cmp);
  ll sum=0;
  ll time=0;
  for(ll i=0;i<n;i++){
    if(i>0)sum+=vec[i].b*time;
    time+=vec[i].a*2;
  }
  cout<<sum<<endl;

  return 0;
}